/*
 * Input.cpp
 *
 *  Created on: 25/04/2010
 *      Author: Nenem
 */

#include "Input.h"
#include "iostream"
using namespace std;

int movUp(SDL_Event *event, Controller *control, Input *input);
int movDown(SDL_Event *event, Controller *control, Input *input);
int movLeft(SDL_Event *event, Controller *control, Input *input);
int movRight(SDL_Event *event, Controller *control, Input *input);
int run(SDL_Event *event, Controller *control, Input *input);
int action(SDL_Event *event,Controller *control, Input *input);

Input::Input() {
	KEY_UP = movUp;
	KEY_DOWN = movDown;
	KEY_LEFT = movLeft;
	KEY_RIGHT = movRight;
	KEY_s = run;
	KEY_a = action;
}

Input::~Input() {
	// TODO Auto-generated destructor stub
}

bool Input::onEvent(SDL_Event *event, Controller *control){
	running = true;
	while(SDL_PollEvent(event)){
		switch(event->key.keysym.sym){
		case SDLK_DOWN:
			KEY_DOWN(event, control, this);
			break;
		case SDLK_UP:
			KEY_UP(event, control, this);
			break;
		case SDLK_LEFT:
			KEY_LEFT(event, control, this);
			break;
		case SDLK_RIGHT:
			KEY_RIGHT(event, control, this);
			break;
		case SDLK_a:
			KEY_a(event,control, this);
			break;
		case SDLK_s:
			KEY_s(event, control, this);
			break;
		case SDLK_ESCAPE:
			running = false;
			break;
		default:
			break;
		}
	}

	return running;
}

int movUp(SDL_Event *event, Controller *control, Input *input){
	if(event->type == SDL_KEYDOWN){
		control->setUP(true);
	}
	else{
		control->setUP(false);
	}
	return 0;
}

int movDown(SDL_Event *event, Controller *control, Input *input){
	if(event->type == SDL_KEYDOWN){
		control->setDOWN(true);
	}else{
		control->setDOWN(false);
	}
	return 0;
}

int movLeft(SDL_Event *event, Controller *control, Input *input){
	if(event->type == SDL_KEYDOWN){
		control->setLEFT(true);
	}
	else{
		control->setLEFT(false);
	}
	return 0;
}

int movRight(SDL_Event *event, Controller *control, Input *input){
	if(event->type == SDL_KEYDOWN){
		control->setRIGHT(true);
	}else{
		control->setRIGHT(false);
	}
	return 0;
}

int run(SDL_Event *event, Controller *control, Input *input){
	if(event->type == SDL_KEYDOWN){
		control->setRUN(true);
	}
	else{
		control->setRUN(false);
	}
	return 0;
}

int action(SDL_Event *event, Controller *control, Input *input){
	if(event->type == SDL_KEYDOWN){
		control->setACTION(true);
	}else{
		control->setACTION(false);
	}
	return 0;
}

